//读写csv文件所需
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <random>
#include<algorithm>
std::ofstream outFile; 
void row_to_string_vector(std::vector<std::string> &record, const std::string& line, char delimiter);
void read(const std::string filename, std::vector<float> &out_vector)
{
    std::vector<std::string> row_element;
    std::string line;
    std::ifstream in(filename,std::ios::in);     
    if (in.fail())  { std::cout << "File not found" <<std::endl; return ; } 
    while(getline(in, line)  && in.good() )
    {
        row_to_string_vector(row_element, line, ',');  //把line里的单元格数字字符提取出来，“,”为单元格分隔符
        for(int i=0, leng=row_element.size(); i<leng; i++){
            out_vector.push_back(atof( row_element[i].c_str() ));
        } 
    }
    in.close();
    return ;
}

void row_to_string_vector(std::vector<std::string> &record, const std::string& line, char delimiter)
{
    int linepos=0;
    char c;
    int linemax=line.length();
    std::string curstring;
    record.clear();
    while(linepos<linemax)
    {
        c = line[linepos];
        if(isdigit(c)||c=='.'||c=='-'){
            curstring+=c;
        }
        else if(c==delimiter&&curstring.size()){
            record.push_back(curstring);
            curstring="";
        }
        ++linepos;
    }
    if(curstring.size())
        record.push_back(curstring);
    return;
}

void write_csv(const std::string filename)
{
    std::random_device rd; //obtain a seed
    std::mt19937 gen(rd()); //mersenne_twister_engine 
    std::uniform_real_distribution<> dist(-1000.0, 1000);
    outFile.open("rtk_recording.csv", std::ios::ate|std::ios::out);
    // 5000*128
    for(int i=1;i<=10;i++){
        for(int j=1;j<=2;j++){
            outFile << dist(gen) << ',';
        }
        outFile <<dist(gen) <<std::endl;
    }   
      
  }
  int main()
  {
      std::string filename = "test.csv" ;
      std::vector<float> out_vector;
      read(filename,out_vector); 
      

      std::cout<<out_vector[0]<<std::endl;
      
  }
  